;
(function (window, angular) {
    'use strict';
    angular.module("Controller.Stock.Split", [])
        .controller("SplitCtrl", ["$scope", "$state", "ybWidget", "ybHttp", "MESG_TYPE", "$filter", "$timeout", "UserContextService", "EventBus", function ($scope, $state, ybWidget, ybHttp, MESG_TYPE, $filter, $timeout, UserContextService, EventBus) {
            $scope.activeFlag = [true, false, false, false, false];
            $scope.subTabFlag = [true, false];
            $scope.datePickerFlag = [false, false];
            $scope.markInfo = {
                allCheckedBill: false,
                allCheckedMaterial: false,
                curRow: -1
            };
            $scope.pageInfo = {
                totalPages: 1,
                totalRows: 0,
                pageSize: 10,
                curPage: 1
            };
            $scope.submitted = false;
            $scope.splitObj = {
                headerInfo: {splitType: 0},
                originalScriptList: [],
                beDisassembleList: []
            };

            $scope.condition = {};
            $scope.toolbarConfig = {
                showAdvanceSearch: false,
                showColConfig: false,
                showMaterielOriginal: false,
                showMaterielDismantling: false
            };
            $scope.dataList = [];
            $scope.detailObj = "";
            $scope.tbConf = {
                fixedWidth: 420,
                scrollWidth: 1220,
                tableCol: [
                    {
                        type: "",
                        name: "拆件单号",
                        dataField: "splitOrder",
                        width: 150,
                        isShow: true,
                        isFixed: false,
                        clickFn: "viewDetail",
                        toSort: false,
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "拆件类型",
                        dataField: "splitTypeStr",
                        width: 110,
                        isShow: true,
                        isFixed: false,
                        toSort: false,
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "拆件状态",
                        dataField: "splitStatusStr",
                        width: 110,
                        isShow: true,
                        isFixed: false,
                        toSort: false,
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "总成件恢复状态",
                        dataField: "restoreStatusStr",
                        width: 120,
                        isShow: true,
                        isFixed: false,
                        toSort: false,
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "审核状态",
                        dataField: "auditStatusStr",
                        width: 100,
                        isShow: true,
                        isFixed: false,
                        toSort: false,
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "备注",
                        dataField: "note",
                        width: 120,
                        isShow: true,
                        isFixed: false,
                        toSort: false,
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "创建人",
                        dataField: "createName",
                        width: 100,
                        isShow: true,
                        isFixed: false,
                        toSort: false,
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "创建时间",
                        dataField: "createDateStr",
                        width: 100,
                        isShow: true,
                        isFixed: false,
                        toSort: false,
                        sortType: ""
                    },
                    {
                        type: "operate",
                        name: "操作",
                        dataField: "",
                        width: 400,
                        isShow: true,
                        isFixed: true,
                        toSort: false,
                        sortType: ""
                    }
                ]
            };

            //详情页面映射字段
            $scope.detailMap = [
                {
                    name: '拆件单号',
                    field: 'splitOrder'
                },
                {
                    name: '创建人',
                    field: 'createName'
                },
                {
                    name: '创建时间',
                    field: 'createDateShow'

                },
                {
                    name: '拆件类型',
                    field: 'splitTypeShow'
                },
                {
                    name: '备注',
                    field: 'note'
                },
                {
                    name: '拆件状态',
                    field: 'splitStatusShow'
                },
                {
                    name: '总成件恢复状态',
                    field: 'restoreStatusShow'
                },
                {
                    name: '审核状态',
                    field: 'auditStatusShow'
                },
                {
                    name: '第一步审核人',
                    field: 'firstAuditName'
                },
                {
                    name: '第一步审核时间',
                    field: 'firstAuditDateShow'
                },
                {
                    name: '第一步审核意见',
                    field: 'firstAuditNote'
                },
                {
                    name: '第二步审核人',
                    field: 'secondAuditName'
                },
                {
                    name: '第二步审核时间',
                    field: 'secondAuditDateShow'
                },
                {
                    name: '第二步审核意见',
                    field: 'secondAuditNote'
                },
                {
                    name: '第三步审核人',
                    field: 'thirdAuditName'
                },
                {
                    name: '第三步审核时间',
                    field: 'thirdAuditDateShow'
                },
                {
                    name: '第三步审核意见',
                    field: 'thirdAuditNote'
                },
                {
                    name: '第四步审核人',
                    field: 'fourthAuditName'
                },
                {
                    name: '第四步审核时间',
                    field: 'fourthAuditDateShow'
                },
                {
                    name: '第四步审核意见',
                    field: 'fourthAuditNote'
                }
            ];
            $scope.nowTime = "";

            //新增零件总成件列表配置项
            $scope.originalScriptTbConf = {
                fixedWidth: 340,
                scrollWidth: 800,
                tableCol: [
                    {
                        type: "",
                        name: "零件编号",
                        dataField: "materialsNo",
                        width: 120,
                        isShow: true,
                        isFixed: false,
                        toSort: false,
                        sortType: ""
                    },

                    {
                        type: "",
                        name: "零件中文名",
                        dataField: "materialsDes",
                        width: 150,
                        isShow: true,
                        isFixed: false,
                        toSort: false,
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "零件类型",
                        dataField: "materialsType",
                        width: 120,
                        isShow: true,
                        isFixed: false,
                        toSort: false,
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "单位",
                        dataField: "unit",
                        width: 120,
                        isShow: true,
                        isFixed: false,
                        toSort: false,
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "数量",
                        dataField: "amount",
                        width: 120,
                        isShow: true,
                        isFixed: false,
                        toSort: false,
                        sortType: "",
                        input: true,
                        inputType: "txt"
                    }
                ]
            };

            //新增零件被拆件列表配置项
            $scope.dismantlingScriptTbConf = {
                fixedWidth: 340,
                scrollWidth: 800,
                tableCol: [
                    {
                        type: "",
                        name: "零件编号",
                        dataField: "materialsNo",
                        width: 120,
                        isShow: true,
                        isFixed: false,
                        toSort: false,
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "零件中文名",
                        dataField: "materialsDes",
                        width: 150,
                        isShow: true,
                        isFixed: false,
                        toSort: false,
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "零件类型",
                        dataField: "materialsType",
                        width: 120,
                        isShow: true,
                        isFixed: false,
                        toSort: false,
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "单位",
                        dataField: "unit",
                        width: 120,
                        isShow: true,
                        isFixed: false,
                        toSort: false,
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "数量",
                        dataField: "amount",
                        width: 120,
                        isShow: true,
                        isFixed: false,
                        toSort: false,
                        sortType: "",
                        input: true,
                        inputType: "txt"
                    }
                ]
            };

            //详情零件总成件列表配置项
            $scope.detailOrigTbConf = {
                scrollWidth: 900,
                tableCol: [
                    {
                        name: "零件编号",
                        width: 120,
                        dataField: "materialsNo"
                    },
                    {
                        name: "零件中文名",
                        width: 150,
                        dataField: "materialsDes"
                    },
                    {
                        name: "零件类型",
                        width: 120,
                        dataField: "materialsType"
                    },
                    {
                        name: "单位",
                        width: 120,
                        dataField: "unit"
                    },
                    {
                        name: "数量",
                        width: 120,
                        dataField: "amount"
                    },
                    {
                        name: "已拆件数量",
                        width: 120,
                        dataField: "splitAmount"
                    },
                    {
                        name: "已恢复数量",
                        width: 120,
                        dataField: "restoreAmount"
                    }
                ]
            };

            //详情零件被拆件列表配置项
            $scope.detailBeDisaTbConf = {
                scrollWidth: 1000,
                tableCol: [
                    {
                        name: "零件编号",
                        width: 120,
                        dataField: "materialsNo"
                    },
                    {
                        name: "零件中文名",
                        width: 150,
                        dataField: "materialsDes"
                    },
                    {
                        name: "零件类型",
                        width: 120,
                        dataField: "materialsType"
                    },
                    {
                        name: "单位",
                        width: 120,
                        dataField: "unit"
                    },
                    {
                        name: "数量",
                        width: 120,
                        dataField: "amount"
                    },
                    {
                        name: "已拆件数量",
                        width: 120,
                        dataField: "splitAmount"
                    },
                    {
                        name: "已入库数量",
                        width: 120,
                        dataField: "inAmount"
                    },
                    {
                        name: "已出库数量",
                        width: 120,
                        dataField: "outAmount"
                    }
                ]
            };

            $scope.inTypeList = [];

            $scope.tabFlag = {};

            $scope.exportParam = {
                sectionUrl: ybHttp.RequestUrl("device", "/split/export"),
                sectionParam: {ids: []},
                allUrl: ybHttp.RequestUrl("device", "/split/exportAll")
            };

            function getBillIds() {
                $scope.exportParam.sectionParam.ids = [];
                angular.forEach($scope.dataList, function (item) {
                    if (!!item.isChecked) {
                        $scope.exportParam.sectionParam.ids.push(item.id);
                    }
                });
            }

            var btnPermissionCode = {
                splitAdd: window.ActionCode.splitAdd,
                splitEdit: window.ActionCode.splitEdit,
                splitDel: window.ActionCode.splitDel,
                splitFirstAudit: window.ActionCode.splitFirstAudit,
                splitSecondAudit: window.ActionCode.splitSecondAudit,
                splitThirdAudit: window.ActionCode.splitThirdAudit,
                splitFourthAudit: window.ActionCode.splitFourthAudit,
                splitPrint: window.ActionCode.splitPrint,
                splitExport: window.ActionCode.splitExport
            };

            $scope.btnPermission = {
                splitAdd: true,
                splitEdit: true,
                splitDel: true,
                splitFirstAudit: true,
                splitSecondAudit: true,
                splitThirdAudit: true,
                splitFourthAudit: true,
                splitPrint: true,
                splitExport: true
            };

            function setBtnPermission() {
                for (var key in btnPermissionCode) {
                    $scope.btnPermission[key] = UserContextService.CheckPermission([btnPermissionCode[key]]);
                }
            }

            $scope.setFixedWidth = function () {
                $scope.tbStyle = {
                    fixedWidth: {left: $scope.tbConf.fixedWidth + "px"}
                };
            };

            $scope.changeTab = function (index) {
                $scope.activeFlag = [false, false, false, false, false];
                $scope.activeFlag[index] = true;
                $scope.submitted = false;
                switch (index) {
                    case 0:
                        initData();
                        break;
                    case 1:
                        break;
                    case 2:
                        break;
                    case 3:
                        break;
                    default:
                        break;
                }
            };

            function initData() {
                $scope.splitObj = {
                    headerInfo: {},
                    originalScriptList: [],
                    beDisassembleList: []
                };
                $scope.splitObj.headerInfo.splitType = 0;
                $scope.tabFlag = {};
                $scope.markInfo.allCheckedMaterial = false;
                $scope.toolbarConfig.showMaterielOriginal = false;
                $scope.toolbarConfig.showMaterielDismantling = false;
            }

            function getDataList(curPage) {
                $scope.markInfo = {
                    allCheckedBill: false,
                    allCheckedMaterial: false,
                    curRow: -1
                };
                var service = "device";
                var reqUrl = "/split/list";
                var param = {};
                param.pageSize = $scope.pageInfo.pageSize;
                if (!!curPage) {
                    $scope.pageInfo.curPage = curPage;
                }
                param.pageNum = $scope.pageInfo.curPage;
                param.filters = angular.copy($scope.condition);
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    angular.forEach(resp.value.list, function (item) {
                        item.isChecked = false;
                    });
                    $scope.pageInfo.totalRows = resp.value.total;
                    $scope.pageInfo.totalPages = resp.value.pages;
                    $scope.dataList = resp.value.list;
                    translateField();
                });
            }


            $scope.delSign = function (code) {
                var codeList = [code];
                delFunc(codeList);
            };

            $scope.delBatch = function () {
                var codeList = [];
                angular.forEach($scope.dataList, function (item) {
                    if (item.isChecked) {
                        codeList.push(item.id);
                    }
                });
                delFunc(codeList);
            };

            function delFunc(CodeList) {
                if (CodeList.length == 0) {
                    ybWidget.ShowMessage('请选择要删除的数据');
                    return;
                }
                ybWidget.ShowMessage("确定要删除吗？", MESG_TYPE.Ask).then(function (data) {
                    var service = "device";
                    ybHttp.Post(service, '/split/remove', CodeList).then(function (data) {
                        if (data.code !== 0) {
                            ybWidget.ShowMessage(data.message);
                            return;
                        }
                        getDataList();
                    })
                })
            }

            $scope.selectRow = function (index) {
                $scope.markInfo.curRow = index
            };

            $scope.tdClick = function (item, fnType) {
                switch (fnType) {
                    case "viewDetail":
                        viewDetail(item);
                        break;
                    default:
                        break;
                }
            };

            $scope.switchToolbar = function (toolbar) {
                if (!!$scope.toolbarConfig["show" + toolbar]) {
                    $scope.toolbarConfig["show" + toolbar] = false;
                } else {
                    $timeout(function () {
                        $scope.toolbarConfig["show" + toolbar] = true;
                    });
                }
            };

            $scope.checkDate = function (obj, startFiled, endFiled) {
                var timeFormatObj = ybWidget.CheckDate(obj[startFiled], obj[endFiled]);
                if (!!timeFormatObj.tStart) {
                    obj[startFiled] = timeFormatObj.tStart;
                }
                if (!!timeFormatObj.tEnd) {
                    obj[endFiled] = timeFormatObj.tEnd;
                }
            };

            $scope.search = function (curpage) {
                getDataList(curpage);
            };

            $scope.reset = function () {
                $scope.condition = {};
            };


            $scope.selectSingle = function (item, list, type) {
                if (!item.isChecked) {
                    $scope.markInfo["allChecked" + type] = false;
                } else {
                    if (!checkAll(list)) {
                        $scope.markInfo["allChecked" + type] = false;
                    } else {
                        $scope.markInfo["allChecked" + type] = true;
                    }
                }
                getBillIds();
            };

            function checkAll(list) {
                var selectAll = false;
                for (var i = 0, len = list.length; i < len; i++) {
                    if (!list[i].isChecked) {
                        selectAll = false;
                        break;
                    }
                    selectAll = true;
                }
                return selectAll;
            }

            $scope.selectAll = function (list, type) {
                angular.forEach(list, function (item) {
                    item.isChecked = $scope.markInfo["allChecked" + type];
                });
                getBillIds();
            };


            function setUserInfo() {
                $scope.splitObj.headerInfo.deptId = $scope.curUser.deptId;
                $scope.splitObj.headerInfo.deptName = $scope.curUser.deptName;
            }

            function viewDetail(item) {
                getDataDetail(item.id).then(function (value) {
                    if (value) {
                        $scope.detailObj = value.value;
                        $scope.changeTab(2);
                        $scope.detailObj.originalDetailList = [];
                        $scope.detailObj.beDismantlingDetailList = [];
                        var orgDetail = $scope.detailObj.materialList.filter(function (item) {
                            return item.matType === 0;
                        });
                        var beDisDetail = $scope.detailObj.materialList.filter(function (item) {
                            return item.matType === 1;
                        });


                        $scope.detailObj.headerInfo.createDateShow = $filter("YbDate")($scope.detailObj.headerInfo.createDate, "yyyy-MM-dd HH:mm:ss");
                        $scope.detailObj.headerInfo.splitTypeShow = $filter("DismantlingType")($scope.detailObj.headerInfo.splitType);
                        $scope.detailObj.headerInfo.splitStatusShow = $filter("DismantlingStatus")($scope.detailObj.headerInfo.splitStatus);
                        $scope.detailObj.headerInfo.restoreStatusShow = $filter("RestoreStatus")($scope.detailObj.headerInfo.restoreStatus);
                        $scope.detailObj.headerInfo.auditStatusShow = $filter("AuditStatus")($scope.detailObj.headerInfo.auditStatus);
                        $scope.detailObj.headerInfo.firstAuditDateShow = $filter("YbDate")($scope.detailObj.headerInfo.firstAuditDate, "yyyy-MM-dd HH:mm:ss");
                        $scope.detailObj.headerInfo.secondAuditDateShow = $filter("YbDate")($scope.detailObj.headerInfo.secondAuditDate, "yyyy-MM-dd HH:mm:ss");
                        $scope.detailObj.headerInfo.thirdAuditDateShow = $filter("YbDate")($scope.detailObj.headerInfo.thirdAuditDate, "yyyy-MM-dd HH:mm:ss");
                        $scope.detailObj.headerInfo.fourthAuditDateShow = $filter("YbDate")($scope.detailObj.headerInfo.fourthAuditDate, "yyyy-MM-dd HH:mm:ss");

                        $scope.detailObj.originalDetailList = orgDetail;
                        $scope.detailObj.beDismantlingDetailList = beDisDetail;

                    }
                })
            }

            var getDataDetail = function (id) {
                var service = "device";
                var reqUrl = "/split/item";

                return ybHttp.Get(service, reqUrl, {id: id}).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return false;
                    }
                    return resp;
                });
            };

            //编辑按钮
            $scope.editData = function (item) {
                getDataDetail(item.id).then(function (resp) {
                    $scope.splitObj = angular.copy(resp.value);
                    $scope.splitObj.originalScriptList = [];
                    $scope.splitObj.beDisassembleList = [];
                    $scope.splitObj.originalScriptList = splitMaterialFn(0, resp.value.materialList);
                    $scope.splitObj.beDisassembleList = splitMaterialFn(1, resp.value.materialList);
                    $scope.changeTab(3);
                })
            };


            //打印按钮
            $scope.printBill = function (item) {
                var id = item.id;
                var billIds = [];
                billIds.push(id);
                var param = {
                    billId: billIds,
                    printType: "SplitPrint"
                };
                ybWidget.SetIsPrintOrPreview(param);
            };

            //新增按钮
            $scope.addData = function () {
                $scope.changeTab(1);
            };

            //选择零件按钮
            $scope.selMateriel = function (e, showMaterielType) {
                if (!!$scope.toolbarConfig[showMaterielType]) {
                    e.stopPropagation();
                } else {
                    $timeout(function () {
                        $scope.toolbarConfig[showMaterielType] = true;
                        $timeout(() => {
                            EventBus.Publish("getMaterial");
                        })
                    });
                }
            };

            //审核按钮
            $scope.viewAudit = function (id) {
                getDataDetail(id).then(function (resp) {
                    $scope.splitObj = angular.copy(resp.value);
                    $scope.splitObj.originalScriptList = [];
                    $scope.splitObj.beDisassembleList = [];
                    $scope.splitObj.originalScriptList = splitMaterialFn(0, resp.value.materialList);
                    $scope.splitObj.beDisassembleList = splitMaterialFn(1, resp.value.materialList);

                    $scope.splitObj.headerInfo.createDateShow = $filter("YbDate")($scope.splitObj.headerInfo.createDate, "yyyy-MM-dd HH:mm:ss");
                    $scope.splitObj.headerInfo.splitTypeShow = $filter("DismantlingType")($scope.splitObj.headerInfo.splitType);
                    $scope.splitObj.headerInfo.splitStatusShow = $filter("DismantlingStatus")($scope.splitObj.headerInfo.splitStatus);
                    $scope.splitObj.headerInfo.restoreStatusShow = $filter("RestoreStatus")($scope.splitObj.headerInfo.restoreStatus);
                    $scope.splitObj.headerInfo.auditStatusShow = $filter("AuditStatus")($scope.splitObj.headerInfo.auditStatus);
                    $scope.splitObj.headerInfo.firstAuditDateShow = $filter("YbDate")($scope.splitObj.headerInfo.firstAuditDate, "yyyy-MM-dd HH:mm:ss");
                    $scope.splitObj.headerInfo.secondAuditDateShow = $filter("YbDate")($scope.splitObj.headerInfo.secondAuditDate, "yyyy-MM-dd HH:mm:ss");
                    $scope.splitObj.headerInfo.thirdAuditDateShow = $filter("YbDate")($scope.splitObj.headerInfo.thirdAuditDate, "yyyy-MM-dd HH:mm:ss");
                    $scope.splitObj.headerInfo.fourthAuditDateShow = $filter("YbDate")($scope.splitObj.headerInfo.fourthAuditDate, "yyyy-MM-dd HH:mm:ss");
                    $scope.changeTab(4);
                });
            };

            $scope.cancel = function () {
                $scope.changeTab(0);
            };


            $scope.delChoosedMaterial = function (index) {
                $scope.splitObj.beDisassembleList.splice(index, 1);
            };

            $scope.checkStock = function (item) {
                item.qtyErr = false;
                if (item.amount % $scope.splitObj.originalScriptList[0].amount !== 0) {
                    item.qtyErr = true;
                    item.qtyErrMsg = "被拆件零件输入数量必须为总成件零件数量的整数倍";
                    return;
                }
            };

            $scope.saveData = function (saveType) {
                if ($scope.splitObj.originalScriptList.length < 1 || $scope.splitObj.beDisassembleList.length < 1) {
                    ybWidget.ShowToaster('error', '被拆件或总成件零件不可为空');
                    return
                }
                if (!$scope.splitObj.originalScriptList[0].amount) {
                    ybWidget.ShowToaster('error', '总成件零件数量不可为空');
                    return
                }
                var checkConut = $scope.splitObj.beDisassembleList.some(function (item) {
                    return item.amount % $scope.splitObj.originalScriptList[0].amount !== 0
                });
                if (checkConut) {
                    ybWidget.ShowToaster('error', '输入数量必须为总成件零件数量的整数倍');
                    return
                }

                var service = "device";
                var param = {};
                var reqUrl = "/split/add";
                if (saveType === "edit") {
                    reqUrl = "/split/update";
                }

                param.headerInfo = angular.copy($scope.splitObj.headerInfo);
                param.materialList = [];
                addMaterialFn(0, $scope.splitObj.originalScriptList, param.materialList);
                addMaterialFn(1, $scope.splitObj.beDisassembleList, param.materialList);
                saveData(service, reqUrl, param).then(function (value) {
                    if (value) {
                        ybWidget.ShowToaster('success', '操作成功');
                        getDataList(1);
                        $scope.changeTab(0);
                    }
                })
            };

            //获取详情时区分materialList的总成件与被拆件
            function splitMaterialFn(matType, objList) {
                var tempArray = [];
                angular.forEach(objList, function (item) {
                    if (item.matType === matType) {
                        tempArray.push(item);
                    }
                });
                return tempArray;
            }

            //新增或编辑保存时，合并materialList的总成件与被拆件
            function addMaterialFn(matType, objList, array) {
                angular.forEach(objList, function (item) {
                    var obj = {};
                    obj.matType = matType;
                    obj.amount = item.amount;
                    obj.materialsDes = item.materialsDes;
                    obj.materialsNo = item.materialsNo;
                    obj.materialsType = item.materialsType;
                    obj.unit = item.unit;
                    obj.id = item.id;
                    array.push(obj);
                });
            }

            function saveData(service, reqUrl, param) {
                return ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return false;
                    }
                    return resp;
                });
            }

            function getNowTime() {
                $scope.nowTime = new Date();
            }

            //翻译字段
            function translateField() {
                angular.forEach($scope.dataList, function (item) {
                    item.splitTypeStr = $filter('DismantlingType')(item.splitType);
                    item.splitStatusStr = $filter('DismantlingStatus')(item.splitStatus);
                    item.restoreStatusStr = $filter('RestoreStatus')(item.restoreStatus);
                    item.auditStatusStr = $filter('AuditStatus')(item.auditStatus);
                    item.createDateStr = $filter('YbDate')(item.createDate, "yyyy-MM-dd HH:mm:ss");
                });
            }

            $scope.switchDataPicker = function (index) {
                $scope.datePickerFlag = [false, false];
                if (angular.isDefined(index)) {
                    $scope.datePickerFlag[index] = true;
                }
            };

            $scope.audit = function (status, id, message) {
                var service = "device",
                    reqUrl = "/split/audit",
                    param = {
                        id: id
                    };
                if (status === 2) {
                    if (!message) {
                        ybWidget.ShowMessage('请输入审核意见');
                        $scope.submitted = true;
                        return;
                    }
                }
                param.status = status;
                param.remark = message;
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    ybWidget.ShowToaster('success', '操作成功');
                    getDataList();
                    $scope.changeTab(0);
                });
            };


            (function () {
                getNowTime();
                getDataList();
                setUserInfo();
                $scope.setFixedWidth();
                UserContextService.SetBtnPermission(setBtnPermission);
            })();
        }])
    ;
})(window, window.angular);